/*
Sample Input
START
from fiwo
hello difh
mars riwosf
earth fnnvk
like fiiwj
END
START
difh, i'm fiwo riwosf.
i fiiwj fnnvk!
END
 

Sample Output
hello, i'm from mars.
i like earth!
 */
package com.yuan.algorithms.team20150724;

import java.util.HashMap;
import java.util.Scanner;

public class HashMap_火星文翻译为英文 {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		HashMap<String, String> map = new HashMap<String, String>(3000);
		sc.next();
		String strVal, strKey;
		while (!(strVal = sc.next()).equals("END")) {
			strKey = sc.next();
			map.put(strKey, strVal);
		}
		sc.next();//接收START
		sc.nextLine();//接收多余的换行符
		String word;
		while (!(word = sc.nextLine()).equals("END")) {
			String temp = "";
			for (int i = 0, len = word.length(); i < len; i++) {
				char t = word.charAt(i);
				if (t >= 'a' && t <= 'z') {
					temp += t;
					if (i == len - 1) {
						System.out.print(search(map, temp));
					}
				} else {
					System.out.print(search(map, temp) + t);
					temp = "";
				}
			}
			System.out.println();
		}
	}

	private static String search(HashMap<String, String> map, String temp) {
		String result = map.get(temp);
		if (result != null) {
			return result;
		}
		return temp;
	}

}
